import React from 'react';
import {injectIntl, language} from './intl';
import PropTypes from 'prop-types';
import {Button, Form, Row, Col, Card, Spin, message, Table} from 'antd';
import routes from './routes';
import {FORM_OPTIONS, FORM_ROW_OPTIONS, PAGE, TABLE, FIXED_COLUMN_WIDTH} from '../constants';
import {conventEnumValueToString, formatAmount} from '../utils';
import WrappedSelect from '../common/WrappedSelect';
import {PERMISSION} from './constants';
import TextInput from 'Shared/components/TextInput';
import DescriptionList from 'ant-design-pro/lib/DescriptionList';
import styles from './style.css';
import Return from '../common/Return';
import {uuid, hasPermissions} from './utils';
import {newOrUpdateOrderValidator} from './validator';
import FileUpload from './FileUpload';
import LocalizeInputNumber from '../common/LocalizeInputNumber';
import {packingType, transportType, currency, saleOrderTransportType, packingBusinessType} from '../Enum';
const FormItem = Form.Item;
const {Description} = DescriptionList;
import WrappedInputNumber from '../common/WrappedInputNumber';
import WrappedPopconfirm from '../common/WrappedPopconfirm';
const autosize = {minRows: 1};
const EMPTY_ARRAY = [];

const rowKey = record => `${record.id}`;
export class Add extends React.PureComponent {
    state = {
        loading: false,
        hasOperat: false,
        isValidate: false,
        isForwarderSearch: false,
    };

    componentDidMount() {
        this.props.init();
        this.ismounted = true;
    }

    componentWillUnmount() {
        this.ismounted = false;
        this.props.onUmount();
    }

    handleFilterChange = (value, name) => {
        if(!this.state.hasOperat)
            this.setState({
                hasOperat: true
            });
        this.props.onConditionsChange(name, value);
    };

    removeFilePath = file => {
        const index = this.props.conditions.attachments && this.props.conditions.attachments.findIndex(item => item.fileId === file.fileId);
        if(index === -1)
            return null;
        const attachments = this.props.conditions.attachments || [];
        attachments.splice(index, 1);
        this.setState({
            hasOperat: true,
        });
        this.props.onConditionsChange('attachments', attachments);
    }
    onChangeUpload = value => {
        const attachments = this.props.conditions.attachments || [];
        attachments.push(value[0]);
        this.setState({
            hasOperat: true,
        });
        this.props.onConditionsChange('attachments', attachments);
    }
    onTableChange = (value, name, id) => {
        const salePackingPartListDetails = this.props.conditions.salePackingPartListDetails || [];
        const tmp = salePackingPartListDetails.map(d => {
            if(d.id === id)
                return Object.assign({}, d, {
                    [name]: value,
                });
            return d;
        });
        this.setState({
            hasOperat: true,
        });
        this.props.onConditionsChange('salePackingPartListDetails', tmp);
    }
    onSubmit = () => {
        const isValid = newOrUpdateOrderValidator(this.props.conditions, this.props.conditions.salePackingPartListDetails);
        if(!isValid) {
            this.setState({
                isValidate: true
            });
            return;
        }
        this.setState({
            loading: true
        });
        this.props.onSubmit().then(success => {
            if(this.ismounted && !success)
                this.setState({
                    loading: false
                });
        });
    };
    onDelete = e => {
        const addedItemId = e.target.dataset.id;
        const tmp = this.props.conditions.salePackingPartListDetails.filter(d => d.id !== addedItemId);
        this.setState({
            hasOperat: true
        });
        this.props.onConditionsChange('salePackingPartListDetails', tmp);
    }
    onDeleteAll = () => {
        this.setState({
            hasOperat: true,
        });
        this.props.onConditionsChange('salePackingPartListDetails', []);
    }
    onClickAddDetailBtn = () => {
        this.props.onConditionsChange('salePackingPartListDetails', [
            ...this.props.conditions.salePackingPartListDetails,
            {
                id: uuid(),
            }
        ]);
        this.setState({
            hasOperat: true
        });
    };
    render() {
        const {details = [], salePackingPartListDetails = [], attachments = []} = this.props.conditions;
        const columns = [
            {
                title: this.props.intl.formatMessage({
                    id: 'add.column.palletCode',
                    defaultMessage: '托盘号'
                }),
                dataIndex: 'palletCode',
                width: 200,
            },
            {
                title: this.props.intl.formatMessage({
                    id: 'add.column.kdBomCode',
                    defaultMessage: 'KDBOM号'
                }),
                dataIndex: 'kdBomCode',
                width: 200,
            }, {
                title: this.props.intl.formatMessage({
                    id: 'add.column.kdBomVersionCode',
                    defaultMessage: 'KDBOM版本号'
                }),
                dataIndex: 'kdBomVersionCode',
                width: 200,
            },
        
            {
                title: this.props.intl.formatMessage({
                    id: 'add.column.quantity',
                    defaultMessage: '数量'
                }),
                dataIndex: 'quantity',
            },
            {
                title: this.props.intl.formatMessage({
                    id: 'add.column.price',
                    defaultMessage: '单价'
                }),
                dataIndex: 'price',
                className: styles.textAlign,
                render: text => formatAmount(text)
            },
            {
                title: this.props.intl.formatMessage({
                    id: 'add.column.totalAmount',
                    defaultMessage: '总价'
                }),
                dataIndex: 'totalAmount',
                className: styles.textAlign,
                render: text => formatAmount(text)
            },
            {
                title: this.props.intl.formatMessage({
                    id: 'add.column.perNetWeight',
                    defaultMessage: '单位净重'
                }),
                dataIndex: 'perNetWeight',
                className: styles.textAlign,
                render: text => formatAmount(text, 3)
            },
            {
                title: this.props.intl.formatMessage({
                    id: 'add.column.netWeight',
                    defaultMessage: '总净重'
                }),
                dataIndex: 'netWeight',
                className: styles.textAlign,
                render: text => formatAmount(text, 3)
            }
        ];
        const partColumns = [
            {
                title: <span className="ant-form-item-required">{this.props.intl.formatMessage({
                    id: 'add.column.partCode',
                    defaultMessage: '备件编号'
                })}</span>,
                dataIndex: 'partCode',
                width: 200,
                render: (text, record) => {
                    const isValidate = (!text) && this.state.isValidate ? {validateStatus: 'error'} : null;
                    return (
                        <FormItem {...isValidate}>
                            <TextInput
                                name="partCode"
                                value={record.partCode}
                                onChange={value => this.onTableChange(value, 'partCode', record.id)} />
                        </FormItem>
                    );
                }
            }, {
                title: <span className="ant-form-item-required">{this.props.intl.formatMessage({
                    id: 'add.column.partName',
                    defaultMessage: '备件名称'
                })}</span>,
                dataIndex: 'partName',
                width: 200,
                render: (text, record) => {
                    const isValidate = (!text) && this.state.isValidate ? {validateStatus: 'error'} : null;
                    return (
                        <FormItem {...isValidate}>
                            <TextInput
                                name="partName"
                                value={record.partName}
                                onChange={value => this.onTableChange(value, 'partName', record.id)} />
                        </FormItem>
                    );
                }
            },
            {
                title: <span className="ant-form-item-required">{this.props.intl.formatMessage({
                    id: 'add.column.partEngName',
                    defaultMessage: '备件英文名称'
                })}</span>,
                dataIndex: 'partEngName',
                render: (text, record) => {
                    const isValidate = (!text) && this.state.isValidate ? {validateStatus: 'error'} : null;
                    return (
                        <FormItem {...isValidate}>
                            <TextInput
                                name="partEngName"
                                value={record.partEngName}
                                onChange={value => this.onTableChange(value, 'partEngName', record.id)} />
                        </FormItem>
                    );
                }
            },
            {
                title: <span className="ant-form-item-required">{this.props.intl.formatMessage({
                    id: 'add.column.quantity',
                    defaultMessage: '数量'
                })}</span>,
                dataIndex: 'quantity',
                render: (text, record) => {
                    const isValidate = (!text) && this.state.isValidate ? {validateStatus: 'error'} : null;
                    return (
                        <FormItem {...isValidate}>
                            <WrappedInputNumber
                                name="quantity"
                                min={0}
                                precision={0}
                                value={record.quantity}
                                onChange={value => this.onTableChange(value, 'quantity', record.id)}/>
                        </FormItem>
                    );
                }
            },
            {
                title: <span className="ant-form-item-required">{this.props.intl.formatMessage({
                    id: 'add.column.price',
                    defaultMessage: '单价'
                })}</span>,
                dataIndex: 'price',
                className: styles.textAlign,
                render: (text, record) => {
                    const isValidate = (!text) && this.state.isValidate ? {validateStatus: 'error'} : null;
                    return (
                        <FormItem {...isValidate}>
                            <WrappedInputNumber
                                name="price"
                                min={0}
                                precision={2}
                                value={record.price}
                                onChange={value => this.onTableChange(value, 'price', record.id)} />
                        </FormItem>
                    );
                }
            },
            {
                title: this.props.intl.formatMessage({
                    id: 'add.column.totalPrice',
                    defaultMessage: '总价'
                }),
                dataIndex: 'totalPrice',
                className: styles.textAlign,
                render: (text, record) => {
                    record.totalPrice = record.price * record.quantity || 0;
                    return (
                        <FormItem>
                            <WrappedInputNumber
                                disabled={true}
                                name="totalPrice"
                                min={0}
                                precision={2}
                                value={record.totalPrice}
                                onChange={value => this.onTableChange(value, 'totalPrice', record.id)} />
                        </FormItem>
                    );
                }
            }, {
                title: details.length ? (
                    <WrappedPopconfirm
                        id="delete"
                        title={this.props.intl.formatMessage({
                            id: 'newPanel.popconfirm.message',
                            defaultMessage: '是否继续?'
                        })}
                        okText={this.props.intl.formatMessage({
                            id: 'newPanel.popconfirm.confirm',
                            defaultMessage: '确认'
                        })}
                        cancelText={this.props.intl.formatMessage({
                            id: 'newPanel.popconfirm.cancel',
                            defaultMessage: '取消'
                        })}
                        onConfirm={this.onDeleteAll}>
                        <a>
                            {this.props.intl.formatMessage({
                                id: 'newPanel.deleteAll',
                                defaultMessage: '清空'
                            })}
                        </a>
                    </WrappedPopconfirm>
                ) : (
                    <a>
                        {this.props.intl.formatMessage({
                            id: 'newPanel.deleteAll',
                            defaultMessage: '清空'
                        })}
                    </a>
                ),
                dataIndex: 'action',
                fixed: 'right',
                width: FIXED_COLUMN_WIDTH,
                render: (text, record) => <a onClick={this.onDelete} key="delete" data-id={record.id}>
                    {this.props.intl.formatMessage({
                        id: 'newPanel.delete',
                        defaultMessage: '删除'
                    })}
                </a>
            }];
        let totalWeight = 0;
        details.forEach(o => {
            totalWeight += (o.netWeight);
        });
        if(this.props.conditions.businessType === packingBusinessType.KD索赔)
            partColumns.splice(2, 0, ...[
                {
                    title: <span className="ant-form-item-required">{this.props.intl.formatMessage({
                        id: 'add.column.kdClaim',
                        defaultMessage: 'KD索赔单号'
                    })}</span>,
                    dataIndex: 'kdClaim',
                    width: 200,
                    render: (text, record) => {
                        const isValidate = (!text) && this.props.conditions.businessType === packingBusinessType.KD索赔 && this.state.isValidate ? {validateStatus: 'error'} : null;
                        return (
                            <FormItem {...isValidate}>
                                <TextInput
                                    name="kdClaim"
                                    value={record.kdClaim}
                                    onChange={value => this.onTableChange(value, 'kdClaim', record.id)} />
                            </FormItem>
                        );
                    }
                },
            ]);
        return (
            <div className={styles.detail}>
                <Spin spinning={this.props.loading || this.state.loading}>
                    <Form className="form-standard">
                        <Card
                            title={this.props.intl.formatMessage({
                                id: 'add.card.title',
                                defaultMessage: '整车包装箱单信息'
                            })}>
                            <Row>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        required
                                        label={this.props.intl.formatMessage({
                                            id: 'add.form.code',
                                            defaultMessage: '编号'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        {this.props.conditions.code}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        required
                                        label={this.props.intl.formatMessage({
                                            id: 'add.form.saleConfirmationrCode',
                                            defaultMessage: '销售确认书编号'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        {this.props.conditions.saleConfirmationrCode}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'add.form.palletCode',
                                            defaultMessage: '托盘号'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        {this.props.conditions.palletCode}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'add.form.batchNumber',
                                            defaultMessage: '批次号'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        {this.props.conditions.batchNumber}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'add.form.containerCode',
                                            defaultMessage: '集装箱号'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        {this.props.conditions.containerCode}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'add.form.sealCode',
                                            defaultMessage: '密封码'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        {this.props.conditions.sealCode}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'add.form.transBatchNumber',
                                            defaultMessage: '发运批次号'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        <TextInput
                                            name="transBatchNumber"
                                            value={this.props.conditions.transBatchNumber}
                                            onBlur={this.handleFilterChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        required
                                        label={this.props.intl.formatMessage({
                                            id: 'add.form.businessType',
                                            defaultMessage: '业务类型'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        {conventEnumValueToString(packingBusinessType, this.props.conditions.businessType)}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        required
                                        label={this.props.intl.formatMessage({
                                            id: 'add.form.currency',
                                            defaultMessage: '币种'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        {conventEnumValueToString(currency, this.props.conditions.currency)}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        required
                                        label={this.props.intl.formatMessage({
                                            id: 'add.form.transportType',
                                            defaultMessage: '运输方式'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        {conventEnumValueToString(saleOrderTransportType, this.props.conditions.transportType)}
                                    </FormItem>
                                </Col>
                                
                                
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        validateStatus={this.state.isValidate && !this.props.conditions.packingType ? 'error' : null}
                                        required
                                        label={this.props.intl.formatMessage({
                                            id: 'add.form.packingType',
                                            defaultMessage: '包装类型'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        <WrappedSelect
                                            name="packingType"
                                            value={this.props.conditions.packingType}
                                            options={packingType.toList(language)}
                                            onChange={this.handleFilterChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'add.form.container',
                                            defaultMessage: '包装规格'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        <span className="value-font">{this.props.conditions.container}</span>
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        validateStatus={this.state.isValidate && !this.props.conditions.length ? 'error' : null}
                                        required
                                        label={this.props.intl.formatMessage({
                                            id: 'add.form.length',
                                            defaultMessage: '长度'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        <LocalizeInputNumber
                                            min={0}
                                            name="length"
                                            value={this.props.conditions.length}
                                            onBlur={this.handleFilterChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        validateStatus={this.state.isValidate && !this.props.conditions.width ? 'error' : null}
                                        required
                                        label={this.props.intl.formatMessage({
                                            id: 'add.form.width',
                                            defaultMessage: '宽度'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        <LocalizeInputNumber
                                            min={0}
                                            name="width"
                                            value={this.props.conditions.width}
                                            onBlur={this.handleFilterChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        validateStatus={this.state.isValidate && !this.props.conditions.height ? 'error' : null}
                                        required
                                        label={this.props.intl.formatMessage({
                                            id: 'add.form.height',
                                            defaultMessage: '高度'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        <LocalizeInputNumber
                                            min={0}
                                            name="height"
                                            value={this.props.conditions.height}
                                            onBlur={this.handleFilterChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        validateStatus={this.state.isValidate && !this.props.conditions.volume ? 'error' : null}
                                        required
                                        label={this.props.intl.formatMessage({
                                            id: 'add.form.volume',
                                            defaultMessage: '体积'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        <LocalizeInputNumber
                                            min={0}
                                            precision={3}
                                            name="volume"
                                            value={this.props.conditions.volume}
                                            onBlur={this.handleFilterChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        validateStatus={this.state.isValidate && !this.props.conditions.netWeight ? 'error' : null}
                                        required
                                        label={this.props.intl.formatMessage({
                                            id: 'add.form.netWeight',
                                            defaultMessage: '净重'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        <LocalizeInputNumber
                                            min={0}
                                            precision={2}
                                            name="netWeight"
                                            value={this.props.conditions.netWeight}
                                            onBlur={this.handleFilterChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        validateStatus={this.state.isValidate && !this.props.conditions.grossWeight ? 'error' : null}
                                        required
                                        label={this.props.intl.formatMessage({
                                            id: 'add.form.grossWeight',
                                            defaultMessage: '毛重'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        <LocalizeInputNumber
                                            min={0}
                                            precision={2}
                                            name="grossWeight"
                                            value={this.props.conditions.grossWeight}
                                            onBlur={this.handleFilterChange} />
                                    </FormItem>
                                </Col>
                            </Row>
                            <Row>
                                <FormItem
                                    label={this.props.intl.formatMessage({
                                        id: 'add.form.remark',
                                        defaultMessage: '备注'
                                    })}
                                    {...FORM_ROW_OPTIONS.item}>
                                    <TextInput type="textarea" name="remark" autosize={autosize}
                                        value={this.props.conditions.remark} onBlur={this.handleFilterChange} />
                                </FormItem>
                            </Row>
                        </Card>
                        <Card
                            title={this.props.intl.formatMessage({
                                id: 'add.details.partTitle',
                                defaultMessage: '整车包装箱单备件清单'
                            })}
                            bordered={false}>
                            <Button
                                type="dashed"
                                icon="plus"
                                block
                                className={styles.plusBtn}
                                onClick={this.onClickAddDetailBtn}>
                                {this.props.intl.formatMessage({
                                    id: 'newPanel.operation.new',
                                    defaultMessage: '新增'
                                })}
                            </Button>
                            <Table className="white-space-nowrap" rowKey={rowKey} columns={partColumns} pagination={false} dataSource={salePackingPartListDetails} {...TABLE} />
                        </Card>
                        <Card
                            title={this.props.intl.formatMessage({
                                id: 'add.details.title',
                                defaultMessage: '整车包装单清单'
                            })}
                            bordered={false}>
                            <Table className="white-space-nowrap" rowKey={rowKey} columns={columns} pagination={false} dataSource={details} {...TABLE} />
                        </Card>
                        <Card title={this.props.intl.formatMessage({
                            id: 'add.title.files',
                            defaultMessage: '附件清单'
                        })}>
                            <Row>
                                <Col {...FORM_OPTIONS.col}>
                                    <FileUpload onChange={this.onChangeUpload}
                                        onRemove={this.removeFilePath}
                                        fileList={attachments || EMPTY_ARRAY}/>
                                </Col>
                            </Row>
          
                        </Card>
                        {this.props.submitable && (
                            <Card type="inner">
                                <Row>
                                    <Col className="col-align-right">
                                        <Button
                                            key="submit"
                                            type="primary"
                                            loading={this.state.loading}
                                            onClick={this.onSubmit}>
                                            {this.props.intl.formatMessage({
                                                id: 'add.btn.submit',
                                                defaultMessage: '保存'
                                            })}
                                        </Button>
                                    </Col>
                                </Row>
                            </Card>
                        )}
                    </Form>
                </Spin>
                <div className="page-toolbar">
                    <Return
                        disabled={this.state.loading}
                        showWarning={this.state.hasOperat}
                        onConfirm={this.props.onCancel} />
                </div>
            </div>
        );
    }
}
Add.propTypes = {
    conditions: PropTypes.object.isRequired,
    loading: PropTypes.bool.isRequired,
    submitable: PropTypes.bool.isRequired,
    onCancel: PropTypes.func.isRequired,
    onConditionsChange: PropTypes.func.isRequired,
    onUmount: PropTypes.func.isRequired,
    id: PropTypes.string,
    intl: PropTypes.object,
};
import {connect} from 'react-redux';
import {
    saveSubmitCondition,
    clearData,
    tableSearch,
    onClickUpdate,
    getDetail,
} from './actions';
import {createSelector} from 'reselect';
import selectorFactory from 'Shared/utils/immutableToJsSelectorFactory';

const getSubmitData = selectorFactory(['page', 'appState', 'submitData']);

const getPermissions = createSelector(
    state => state.getIn(['page', 'domainData', 'permission', 'data']),
    (state, ownProps) => ownProps.id,
    state => state.getIn(['page', 'domainData', 'detail', 'data']),
    (permissions, id, detail) => {
        const {options = EMPTY_ARRAY} = detail.toJS();
        const data = permissions.toJS();
        const submitable = id ? data.includes(PERMISSION.update) && options.includes(PERMISSION.update)
            : data.includes(PERMISSION.add);
        return submitable;
    }
);
const mapStateToProps = (state, ownProps) => ({
    id: ownProps.id,
    submitable: getPermissions(state, ownProps),
    loading: state.getIn(['page', 'domainData', 'detail', 'isFetching']),
    conditions: getSubmitData(state),
});

const mapDispatchToProps = (dispatch, ownProps) => ({
    init: () => dispatch(getDetail(ownProps.id)),
    onConditionsChange: (name, value) => dispatch(saveSubmitCondition(name, value)),
    onSubmit: status =>
        dispatch(onClickUpdate(ownProps.id, status)).then(res => {
            if(res.ok) {
                dispatch(tableSearch({
                    pageIndex: PAGE.index
                }));
                ownProps.history.push(routes.query.url());
            }
            return res.ok;
        }),
    onCancel: () => {
        ownProps.history.push(routes.query.url());
    },
    onUmount: () => dispatch(clearData()),
});

export default connect(
    mapStateToProps,
    mapDispatchToProps
)(injectIntl(Add));
